package com.ultron.app.modules.user.service.userRoleMenu.impl;

import com.ultron.app.entity.system.ResultEnum;
import com.ultron.app.exception.ServiceException;
import com.ultron.app.entity.base.BaseBatchBO;
import com.ultron.app.modules.user.entity.userRoleMenu.UserRoleMenuPO;
import com.ultron.app.modules.user.entity.userRoleMenu.bo.UserRoleMenuBO;
import com.ultron.app.modules.user.service.userRoleMenu.IUserRoleMenuBaseService;
import com.ultron.app.modules.user.service.userRoleMenu.IUserRoleMenuBatchCreateService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

/**
 * 标题：用户角色菜单权限(批量新增服务实现)
 * 说明：用户角色菜单权限(批量新增服务实现),自定义批量新增据服务实现
 * 时间：2024-2-27
 * 作者：admin
 */
@Service
public class UserRoleMenuBatchCreateServiceImpl implements IUserRoleMenuBatchCreateService {
    
    
    /**
     * 基础通用服务
     */
    @Autowired
    private IUserRoleMenuBaseService baseService;
    /**
     * 批量新增数据
     * @param req
     * @return 新增数据的组件ID集合
     */
    @Override
    public List<Long> batchCreate(BaseBatchBO<UserRoleMenuBO> req) {
        List<Long> rsp = new ArrayList<>();
        //入参效验
        this.validParams(req);
        //执行核心逻辑前调用
        this.beforeToDo(req);
        List<UserRoleMenuPO> poList = req.getList().stream().map(k->{
            UserRoleMenuPO po = new UserRoleMenuPO(k);
            return po;
        }).collect(Collectors.toList());
        boolean state = baseService.saveBatch(poList);
        if(!state){
            throw new ServiceException(ResultEnum.FAILURE, "批量新增数据失败");
        }
        rsp = poList.stream().map(UserRoleMenuPO::getId).collect(Collectors.toList());
        return rsp;
    }
    /**
     * 类通用入参校验
     *
     * @param req
     */
    private void validParams(BaseBatchBO<UserRoleMenuBO> req) {
        if (null == req) {
            throw new ServiceException(ResultEnum.PARAM_MISS, "入参不能为空");
        } else {
            if(null == req || req.getList().size() == 0){
                throw new ServiceException(ResultEnum.PARAM_MISS, "批量新增入参不能为空");
            }
            List<UserRoleMenuBO> list = req.getList();
            for (UserRoleMenuBO i : list) {
                
                
                
                
                
                
                
                
                
                
                
                
                
                
            }
        }
    }
    /**
     * 类通用执行前调用逻辑
     *
     * @param req 入参
     */
    private void beforeToDo(BaseBatchBO<UserRoleMenuBO> req) {
        // TODO 执行前调用逻辑
    }
}